MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamically pass Cobol variable

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Tue Mar 24, 2020 12:38 pm    Post subject: Dynamically pass Cobol variable Reply with quote

I have a file of 600 fields, the requirement is to handle 50 to 60 fields with the simple conditions and skips the record from being written into the output file.

I have to create a program to dynamically get the field name as input and perform the condition.


A Parm file will have a list of field names and operation

Code:

FIELDNAME                      OPERATION                            VALUE 
FIELD1                             =                                45
FIELD3                             >                                50
FIELD4                             =                                'TEST'
 

Is it possible to create a COBOL program that dynamically pass these as input and performs the condition check?

example :

This should basically do the following

Code:

READ INPUTFILE
MOVE 'N' to SKIP-REC
IF FIELD1 = 45
MOVE 'Y' TO SKIP-REC
END-IF
IF FIELD3 > 50
MOVE 'Y' TO SKIP-REC
END-IF
IF FIELD4 = 'TEST'
MOVE 'Y' TO SKIP-REC
END-IF

IF SKIP-REC = 'N'
MOVE INPUT-RECORD TO OUTPUT-RECORD
WRITE OUTPUT-RECORD
END IF.


Thanks
Magesh
Back to top
View user's profile Send private message
Robert Sample
Beginner


Joined: 15 Dec 2009
Posts: 12
Topics: 0
Location: Atlanta

PostPosted: Tue Mar 24, 2020 3:26 pm    Post subject: Reply with quote

Generally, yes although what you want to do can get tricky. Probably the easiest way is to create a table to convert field names into starting position, length, and data type (unless zoned decimal is all you have). Use reference modification to move the field into a testing variable and use the appropriate condition and test against the input value (which you may need to use FUNCTION NUMVAL to make numeric).
Back to top
View user's profile Send private message
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Tue Mar 24, 2020 5:15 pm    Post subject: Reply with quote

Thanks, Robert. Good idea.


Regards,
Magesh
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 621
Topics: 173
Location: Stockholm, Sweden

PostPosted: Wed Mar 25, 2020 2:57 am    Post subject: Reply with quote

A lot depends on how often the parm file will change. If the solution is a simple, flexible one, will there be a use for it for other problems?

Another way might (?) be to write a program that reads the parm file and generates the cobol source code for your comparison (can't see that as being too difficult). IF the fields in your parm file refer to fields in a copybook, then it becomes even easier. For example, your generated code might become something like:-
Code:

01  field-copybook.
      copy field.
.
.
.
evaluate true
  when field1 not numeric
      set skip-rec-no       to true  (I'm a great believer in 88-variables :-) )
  when field1 = 45
    set skip-rec-yes       to true 
end-evaluate

evaluate true
  when field3 not numeric
      set skip-rec-no       to true
  when field1 > 50
    set skip-rec-yes       to true
end-evaluate


Your solution (granted, just an example) would result in if field1 is okay, but not field3, the record would be written. It depends on whether the tests are OR'ed or AND'ed.

The solution above assumes that if any field doesn't meet the criteria, then the record won't be written.

This solution could be considered as overkill, I'm not sure.

Robert's idea of using FUNCTION NUMVAL has (IMO) one major drawback. If the field being tested isn't numeric, expect a big fat abend from the NUMVAL call.
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group