I would like to know if and how we can write records to a dataset using just JCL.

Scenario:

Lets say, these 3 Files were sent via FTPS in the previous steps:

FILE1_%%$ODATE.%%TIME
FILE2_%%$ODATE.%%TIME
FILE3_%%$ODATE.%%TIME

Requirement:

Once all 3 files are transferred, we have to send them a so-called "flagfile". This flagfile must contain the 3 filenames, so that the downstream application knows, what filenames we sent to them, since %%$ODATE and %%TIME are Control-M Variables and can change after each run.

Considering that STEP1,STEP2 and STEP3 gets the filenames to be transmitted after the substitution of %%$ODATE and %%TIME just before submission, would it be possible that the STEP4 has instream data just like the example below that could also be substituted? This would get you the file names in the SORTOUT?