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

Displaying record from custom table

Former Member
0 Likes
1,527

I have a custom table ztable (kunnr, vbeln, erdat, erzet, flag). Using these values I would like to display the following

Client Number (4) = '1234'

Filler (6) = space.

Record Type (1) = 'A'

Client Number (15) = vrkpa-kunnr

Customer Name (30) = adrc-name1

This information should be displayed in the following way:

1234 A0012345 Walmart

Can someone help me with this code.

Thank you!

11 REPLIES 11
Read only

Former Member
0 Likes
1,354

How do you want these displayed? On a screen? In a report?

- April King

Read only

Former Member
0 Likes
1,354

For now, I can display it on the screen as output. Eventually i need to create a txt file out of it. More on that later.

Read only

Former Member
0 Likes
1,354

hi

use concatenate statement.

CONCATENATE Client_number filler record_type cline_no cust_name INTO C1.

WRITE C1.

regards,

madhu

Read only

Former Member
0 Likes
1,354

I need to format the information based on my specs and display it

for eg : MANDT is length 3, but it my out it needs to be 4

Customer Number KUNNR is length 10, but i need to display it as 15 left justified, right fill with spaces

Customer Name ADRC-NAME1 is length 40, but i need to display it as 30

Read only

0 Likes
1,354

Just to clarify, are the format discrepancies between the table where you're pulling the data and your custom table? Or are the discrepancies between your custom table and how you want to display the fields? If it's the first case, then you can define the fields of your table as whatever formats you need and adjust the fields when you move the data to them. If it's the second case, then you can define working storage fields in the formats that you need and adjust them as you move the data from your custom table to those fields.

Some fields will automatically have the data adjusted when you assign the values (i.e. the customer name will automatically be truncated to a length of 30). For the customer number, you can use something like this:

ztable-kunnr+0(10) = vrpa-kunnr.

ztable-kunnr+10(5) = spaces.

- April

Read only

Former Member
0 Likes
1,354

Hi,

concatenate cl_number filler record_tp cl_num2 cu_name into statement.

NOTE: But make sure that the attributes of the source and target fields should be same. In this case you shown Client Number (15) but vrkpa-kunnr declared as just 10 char and Customer Name (30) but adrc-name1 declared as 40 char.

For client number, unnecessarly we are using 5 char memory and in second case 10 chars data will be truncated when it moves from the source to taget fields.

Thanks

Satya

Read only

Former Member
0 Likes
1,354

Hi April

Its the second case, the discrepancy is in my table and the value it needs to be displayed. I am thinking I need to create an ITAB, and then pull the values from vrkpa and adrc for that kunnr into my itab. Then in my itab I can set them to whatever format I want and then display them using loop. Can you help me with this code.

Read only

0 Likes
1,354

Sure. Yes, it would probably be easiest to put the records that you want to display in an itab and then loop through that to display. Are you going to use all records from your custom table? If so, you can do something like this:

DATA wa_ztable TYPE ztable.

DATA: begin of itab occurs 0,

client type n length 4,

custnum type c length 15,

custname type c length 30,

end of itab.

DATA filler type c length 6 value space.

DATA rectype type c length 1 value 'A'.

DATA w_record type c length 16.

SELECT * FROM ztable INTO wa_ztable.

concatenate '0' wa_ztable-mandt into itab-client.

itab-custnum+0(10) = wa_ztable-kunnr.

itab-custnum+10(5) = space.

itab-custname = wa_ztable-name1.

append itab.

clear itab.

ENDSELECT.

LOOP AT itab.

concatenate rectype itab-custnum into w_record.

write:/ itab-client, filler, w_record, itab-custname.

ENDLOOP.

I think this sounds like what you're looking for.

- April

Read only

Former Member
0 Likes
1,354

data: begin of itab1 occurs 0,

clientnumber(4) type c,

filler(2) type c,

recordtype(1) type c value 'A',

customernumber(15) type c,

customername(30) type c,

customeraddress1(30) type c,

customeraddress2(30) type c,

customercity(17) type c,

customerstate(2) type c,

customerzip(9) type c,

customercountry(17) type c,

customercountrycode(3) type c,

customerphnum(10) type c,

end of itab.

This is what I have so far. Now I need to look into ztable(kunnr, vbeln, erdat, erzet, flag) for flag = space and initialize

customernumber = vrkpa-kunnr

customername = adrc-name1 and so on

Then I need to set flag in ztable as 'X'

Read only

Former Member
0 Likes
1,354

Quite close. But take a look at my itab that I have created. I need to get all the address info from table adrc. My ztable only contains (vbeln, kunnr, erdat, erzet, flag) and I need to look into ztable and pull out rows into my itab only when flag = blank

data: begin of itab1 occurs 0,

clientnumber(4) type c value '1234',

filler(2) type c,

recordtype(1) type c value 'A',

customernumber(15) type c,

customername(30) type c,

customeraddress1(30) type c,

customeraddress2(30) type c,

customercity(17) type c,

customerstate(2) type c,

customerzip(9) type c,

customercountry(17) type c,

customercountrycode(3) type c,

customerphnum(10) type c,

end of itab.

Read only

0 Likes
1,354

Okay, I see. Is your client number always going to be '1234'? If not, then do not assign a value to it. Otherwise, you'll want to assign the value during your selection statement because the field will be emptied each time you clear the itab line.The same thing goes for your record type 'A'. You need an address number, a date, and a nation as the key for table ADRC (so you need to put the necessary values into w_nation and w_begda). I'm not sure if your customer number corresponds to the address number. Try this:

DATA wa_ztable TYPE ztable.

DATA wa_adrc TYPE adrc.

DATA w_nation type adrc-nation.

DATA w_begda type sy-datum.

DATA: begin of itab occurs 0,

clientnumber(4) type c,

filler(2) type c,

recordtype(1) type c,

customernumber(15) type c,

customername(30) type c,

customeraddress1(30) type c,

customeraddress2(30) type c,

customercity(17) type c,

customerstate(2) type c,

customerzip(9) type c,

customercountry(17) type c,

customercountrycode(3) type c,

customerphnum(10) type c,

end of itab.

w_begda = (put your date here).

w_nation = (put your nation code here).

SELECT * FROM ztable INTO wa_ztable WHERE flag = space.

itab-clientnumber = '1234'.

itab-filler = space.

itab-rectype = 'A'.

itab-customernumber+0(10) = wa_ztable-kunnr.

itab-customernumber+10(5) = space.

SELECT SINGLE * FROM TABLE adrc INTO wa_adrc WHERE

ADDRNUMBER = wa_ztable-kunnr AND NATION = w_nation AND DATE_FROM = w_begda.

itab-customername = wa_adrc-name1.

  • itab-customeraddress1 = wa_adrc-

  • itab-customeraddress2 = wa_adrc-

itab-customercity = wa_adrc-city1.

itab-customerstate = wa_adrc-regiogroup.

itab-customerzip = wa_adrc-post_code1.

  • itab-customercountry = wa_adrc-

itab-customercountrycode = wa_adrc-country.

itab-customerphnum = wa_adrc-tel_number.

append itab.

clear itab.

ENDSELECT.

LOOP AT itab.

*Insert your code to display line here (can just list each itab field, or use column numbers if you want to create spaces between the fields)

ENDLOOP.

Note on the * lines: I don't see a field for the country text. For the address lines, you will probably have to concatenate values from ADRC-HOUSE_NUM1 and ADRC-STREET, and possibly also use ADRC-PO_BOX as well.

- April

Message was edited by:

April King