01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING".
01 NAME2 PIC X(13).
now I want to display the value of NAME1 in reverse order
i.e value should be displayed as "GNIMMARGORP LOBOC"
HOW can I do that ??? please let me know if any one knows
it.

Answers were Sorted based on User's Feedback



01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / mr2981

to reverse the string use REVERSE function

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING".
01 NAME2 PIC X(13).

MOVE FUNCTION REVERSE(NAME1) TO NAME2.

Is This Answer Correct ?    34 Yes 3 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / elizabeth

Using reference modification each character can be
extracted and placed in the next string in any order

Is This Answer Correct ?    11 Yes 0 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / rajani

working-storage section.
01 name1 pic x(17) value 'cobol programming'.
01 name2 pic x(17).
01 i pic 99.
01 j pic 99 value 1.
procedure division.
perform para varying i from 17 by -1 until i<1.
display name2.
stop run
para.
move name1(i:1) to name2(j:1).
add 1 to j.

Is This Answer Correct ?    11 Yes 1 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / jagan

This should convert the string in reverse order without any
built-in functions . And one more thing is COBOL PROGRAMMING
is actually 17 characters.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 NAME-1 PIC X(17) 'COBOL PROGRAMMING'
01 NAME-2
05 NAME-21 PIC X(1) OCCURS 17 TIMES.

01 I PIC X(2)
01 J PIC X(2)


PROCEDURE DIVISON.
MAIN-PARA.
MOVE 0 TO J.
PERFORM READ-NAME VARYING I FROM 17 BY -1 UNTIL I > 0.
STOP RUN.


READ-NAME
ADD 1 TO J.
MOVE NAME-1(I) TO NAME-21(J).
END-READ-NAME.

Correct me in case any problem with above code.

Is This Answer Correct ?    7 Yes 4 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / sairanga

procedure division.
move name1(17:1) to name2(1:1).
move name1(16:1) to name2(2:1).
move name1(15:1) to name2(3:1).
.
.
.

move name1(2:1) to name2(16:1).
move name1(1:1) to name2(17:1).
display name2.
stop run.

Is This Answer Correct ?    3 Yes 1 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / sunil

Hi,

Please try this code it should work.

IDENTIFICATION DIVISION.
PROGRAM-ID. MID.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR1 PIC X(17) VALUE IS 'COBOL PROGRAMMING'.
01 STR2 PIC X(1).
01 STR3 PIC X(17) VALUE SPACE.
01 STRLEN PIC 9(2).

PROCEDURE DIVISION.
INSPECT STR1 TALLYING STRLEN FOR CHARACTERS.
DISPLAY STRLEN.
PERFORM UNTIL STRLEN < 1

MOVE STR1(STRLEN:1) TO STR2
DISPLAY STR2
STRING
STR3 DELIMITED BY SPACE
STR2 DELIMITED BY SPACE
INTO STR3
COMPUTE STRLEN STRLEN - 1
DISPLAY STR3
END-PERFORM.
DISPLAY STR3.
STOP RUN.


Thanks,
Sunil

Is This Answer Correct ?    0 Yes 0 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / ankur kar

In order to reverse the String the only way is by declaring
the string as an array and then sequentially arrage the
array based on the asending/desending order of the array
and then display the sequential result accordingly.
Otherwise there is no command in COBOL that will allow the
string to be displayed in the reverse order.

Is This Answer Correct ?    3 Yes 4 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / devraj pradhan

as per my knowledge this problem can be solve by STRING AND
UNSTRING COMMAND as in that there is REPLACING option is
there by which any string can be replace in reverse order

Is This Answer Correct ?    0 Yes 4 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / satya

As per my knowledge we can solve this problem with use of
STRING AND UNSTRING commands,first UNSTRING the give string
and add all the characters according to our choice by using
STRING COMMAND.

Is This Answer Correct ?    1 Yes 6 No

01 NAME1 PIC X(13) VALUE "COBOL PROGRAMMING". 01 NAME2 PIC X(13). now I want to ..

Answer / rajul

just define
01 name2 picX(13) right justified.

and then use move stmt
move name1 to name2.

Is This Answer Correct ?    2 Yes 13 No

Post New Answer

More COBOL Interview Questions

01 a pic 9(6) value is 123456 01 b pic 9(3) move a to b wht will be the value ?

6 Answers   Patni,


What are differences between COBOL and java ? why we are giving more preference to COBOL ?

3 Answers   TCS,


consider the following piece of code 01 GROSS-PAY 05 BASIC-PAY PIC 9(5) 05 ALLOWENCES PIC 9(3) if BASIC-PAY has a value 1000 and ALLOWENCES has a value of 250,what will be displayed by the statement DISPLAY GROSS-PAY a.1250 b.01000250 c.01250 d.1.250

3 Answers   TCS,


If we use GO BACK instead of STOP RUN in cobol?

2 Answers   Temenos,


I have sequential file recl 1000 i want to add another 15 bytes to it. The record length should not change..How?

1 Answers   CTS, HCL,






Read a flat file and write last but one (I have n records in a file I have to write n-1th) record in another flat file. Could you please provide me the code in COBOL?

1 Answers  


01 a pic 9(3) value is 123 01 b pic 9(6) move a to b wht will be the value ? and 01 a pic x(6) value is abc 01 b pic x(3) move a to b wht will be the value ?

7 Answers   Patni,


i have a file which contains records like 10,30,90,50,20,40,80,60,70 i want to display these records in reverse order like 70,60,80,40,20,50,90,30,10 please give me the cobol code (do not sort the records)

3 Answers   Cap Gemini, Mind Tree,


Will the variable POS in the following code have a value of 2 or not? 01 POS PIC S9(4) COMP VALUE 2. 01 FIRST-NAME PIC X(10) VALUE 'ABC'. 01 LAST-NAME PIC X(10) VALUE 'XYZ'. 01 NAME PIC X(20) VALUE SPACES. STRING FIRST-NAME DELIMITED BY SPACES ' ' DELIMITED BY SIZE LAST-NAME DELIMITED BY SPACES INTO NAME WITH POINTER POS

2 Answers  


if a>b continue display x. dispaly y. end-if display 1 display 2. display 3. what should be my output ?

3 Answers  


i have n records in one file and in this file there is some fields and i want to count that how many sharma in my file so plz give the coding that how we read sharma ?

2 Answers  


What is the difference between perform … with test after and perform … with test before?

0 Answers  


Categories