Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Display data in binary format

Former Member
0 Likes
2,316

I have to read data from a flat file and convert that to binary format and display it in binary itself(0s and 1s). Reading stuff I can do but i cannot convert that to binary and display it in the form of a report.

I have looked into some standard function modules but i am not sure of the input parameters required by those modules. Can somebody please help me ?

1 ACCEPTED SOLUTION
Read only

sridhar_k1
Active Contributor
0 Likes
1,748

If your flat file on appserver? then try the following code:

data: v_hex type x,

v_bit type n.

open dataset file_name for input in <b>binary mode</b>.

do.

read dataset file_name into v_hex.

if sy-subrc ne 0.

close dataset file_name

exit.

endif

do 8 times.

get bit sy-index of v_hex into v_bit.

write v_bit no-gap.

enddo.

enddo.

Regards

Sridahr

Message was edited by: Sridhar K

8 REPLIES 8
Read only

Former Member
0 Likes
1,748

Hi,

Looks like this FM C13Z_FILE_DOWNLOAD_BINARY will be helpful to you.

Regards,

ravi

Read only

0 Likes
1,748

Hi Ravi,

I greatly appreciate you replying to my problem. But this FM is not enough for my purpose.

The FM C13Z_FILE_DOWNLOAD_BINARY can only download the file in binary format to the presentation server but i need to read that file in binary itself and display it in the form of a report. I can read that file as well but this data is converted to ASCII when read and the 0s and 1s seems to disappear.

I have already tried with this FM but am facing difficulties in displaying the binary data.

Read only

0 Likes
1,748

Hi Kirti,

Do something on this lines:

data: CHAR(2) type C value '14',

INT TYPE I,

hex type x.

INT = CHAR.

hex = int.

  • write: hex.

case hex.

when '00'.

write: '0000'.

when '01'.

write: '0001'.

when '02'.

write: '0010'.

when '03'.

write: '0011'.

when '04'.

write: '0100'.

when '05'.

write: '0101'.

when '06'.

write: '0110'.

when '07'.

write: '0111'.

when '08'.

write: '1000'.

when '09'.

write: '1001'.

when '0A'.

write: '1010'.

when '0B'.

write: '1011'.

when '0C'.

write: '1100'.

when '0D'.

write: '1101'.

when '0E'.

write: '1110'.

when '0F'.

write: '1111'.

endcase.

Regards,

ravi

Read only

0 Likes
1,748

Hi Ravi,

Thanks for the help. I have checked with your lines but it can only display numbers in binary. In order to display alphabets as well as special characters the code needs to be modified manifold and the binary code of every character has to be checked with. Also this may take lots of processing time and such performance issues won't be accepted by my seniors.

Thanks and Regards,

Kirti Bhushan.

Read only

Former Member
0 Likes
1,748

Hai Kirti

Check the following Code

Flat file Contents is :

MAT991 CCOUP Srinivas material01 Kg

MAT992 CCOUP Srinivas material01 Kg

MAT993 CCOUP Srinivas material01 Kg

data : begin of it_mara occurs 0,

matnr like mara-matnr,

mbrsh like mara-mbrsh,

mtart like mara-mtart,

maktx like makt-maktx,

meins like mara-meins,

end of it_mara.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\new.txt'

FILETYPE = 'BIN'

TABLES

DATA_TAB = it_mara.

loop at it_mara.

write : it_mara-matnr.

endloop.

Thanks & regards

Sreenivasulu P

Read only

0 Likes
1,748

Thanks for the code Sreenivasulu but this will display the data in the form of characters itself and what i want is 0s and 1s.

Can you please suggest something that can display it in the form of 0s and 1s.

Thanks and Regards,

Kirti Bhushan

Read only

sridhar_k1
Active Contributor
0 Likes
1,749

If your flat file on appserver? then try the following code:

data: v_hex type x,

v_bit type n.

open dataset file_name for input in <b>binary mode</b>.

do.

read dataset file_name into v_hex.

if sy-subrc ne 0.

close dataset file_name

exit.

endif

do 8 times.

get bit sy-index of v_hex into v_bit.

write v_bit no-gap.

enddo.

enddo.

Regards

Sridahr

Message was edited by: Sridhar K

Read only

0 Likes
1,748

Hi Sridhar,

Thanks a ton for the solution you provided me for my problem. Its workin fine and I am very much satisfied with the results. Thanks again and thanks a lot.

Regards,

Kirti Bhushan.