ā2013 Feb 21 8:24 PM
Hello experts.
i am learning ABAP. i found in very interesting yet a bit confusing programming language.
i am in need of some help from an expert for my problems.
I have a flow diagram for which i have tried coding. but in some situations i am unable to find a fit solution for the problem.
the code is below and diagram is attached in a file.
I HAVE DIVIDED THE DIAGRAM IN STEPS AND CODED ACCORDINGLY.
CODE :
TABLES: ZPATCORE, ZNPAT, ZNBEW.
DATA: wa_ZPATSE TYPE ZPATSE,
wa_ZPATCORE TYPE ZPATCORE,
wa_ZNBEW TYPE ZNBEW,
wa_ZNPAT TYPE ZNPAT
date_today TYPE d,
alldays TYPE i.
DATA: ITAB1 LIKE ZPATCORE, /////// comment ////////// creating internal tables for Database tables.
ITAB2 LIKE ZNPAT,
ITAB3 LIKE ZNBEW.
SELECT * FROM ZAPTCORE INTO ITAB1.
SELECT * FROM ZNPAT INTO ITAB2.
SELECT * FROM ZNBEW INTO ITAB3.
1) Read all combination of PatID and FallID and BettNr from ZNBEW where:
Fach=āitsā and behend=ā31.12.9999ā
select PatID,FallID,BettNr
from ZNBEW
into wa_ZNBEW
where fach EQ āitsā
and behend EQ ā31.12.9999ā
and NOT BettNr eq ā99ā. //////////// comment ////////////// the value with znbew-BettNr NOT EQ ā99ā is not passed further.
2) If combination of PatID and FallID exists in ZPATCORE and ZNBEW-BettNr not= ā99ā
IF sy-subrc EQ 0 wa_ZPATCORE IS INITIAL.
Select PatID ,FallID
From ZPATCORE
Into wa_ZPATCORE
Where PatID EQ wa_ZNBEW-PatID
And FallID EQ wa_ZNBEW-FallID.
3) Read name and vorname and gebudat from ZNPAT where id=PatID
4) Read ifdnr and itstag from ZPATCORE.
IF sy-subrc EQ 0.
SELECT * FROM ZNPAT INTO TABLE ITAB2
FOR ALL ENTRIES IN ITAB1
WHERE PatID = ITAB1-PatID.
* Alldays=date _today-itstag
date_ today = sy_datum .
alldays= date_today ā wa_ZPATCORE-itstag //////// as i know that days= date_1- date_2 or i should use a function module called "C14B_DIFF_BT_2_DATES "
For String output
SELECT PatID, Ifdnr, BettNr FROM ZNBEW INTO TABLE ITAB3
FOR ALL ENTRIES IN ITAB2
WHERE PatID = ITAB2-PatID. ////////////////////////// for the value of BettNr from table znbew according to PatID of table ZNPAT
LOOP AT ITAB3.
Write: / āifd:ā ITAB3-Ifdnr,
āBett:ā ITAB3-BettNr ,
āName,Vorname:ā ITAB3-Name ITAB3-Vorname,
ITAB3-Gebdat,
āTag:āITAB3-alldays.
END LOOP.
xxx---------------------------------------------------------------------------------------xxx
DATABASE TABLES USED FOR THE DIAGRAM AND DESCRIPTION.
Tables:
ZNBEW:
-lfdnr (integer)
-PatID (integer)
-FallID (integer)
-BettNr (integer)
-fach (string)
-behend (date)
=>Comment: There are lines with the same PatID and FallID, lfdnr is a number from 1 to n.
at every combination of PatID and FallID, lfdnr is only once there
Example:
PatID FallID lfdnr
4 1 1
4 1 2
4 1 3
4 3 1
ZPATCORE:
-PatID
-FallID
-BewID
-aufnahmestatus_vollst (char)
-entlassstatus_vollst (char)
-itstag(date)
-ifdnr
=>Comment: There Every line with PatID and FallID has a different value of BewID
ZNPAT:
-PatID
-Name(string)
-Vorname(string)
-Gebudat(date)
**alldays=date_today-itstag
alldays is the number of days beetween date_today and itstag.
itstag is allways a date earlier than date_today.
MY QUESTIONS ARE :
1) How to loop for the next combination? (from flow diagram)
2) Is it ok to use āwa_ZPATCORE-itstagā for the calculation of āalldaysā calculation?
(* Alldays=date _today-itstag)
3) I have used āFOR ALL ENTRIESā instead of joins? So is it ok to use them or joins are more beneficial?
4) will the code work as the diagram intended it to work?
***** please note flow diagram is in a file 'img.png' attached to this post.
thank you.
ā2013 Feb 21 9:18 PM
Hi Ojaswa,
It's good that u r trying things out. Based on the diagram flow, I'll try to help u with the concept.
Getting the code ready made for u is a bit of an exercise here.
-> loop / endlloop will take u to next combinations
-> dont use joins in any real time scenarios. Instead, Use for all entries and dont hesitate to do more processing in internal tables Using Read , Binary search
declare internal tables of standard types.
select * from znbew into table t_znbew
where fach = 'its' and behend = '31.12.9999'.
if sy-subrc eq 0.
select statement for zpatcore into table t_zpatcore for all entries in t_znbew
select statement for znpat into table t_znpat for all entries in t_zpatcore
endif.
sort the internal tables based on key fields.
Loop at t_znbew into wa_znbew.
read table t_zpatcore into wa_zpatcore
if sy-subrc eq 0 and wa_znbew-bettnr ne '-99'.
read table t_znpat into wa_znpat with key id = wa_znbew-patid.
if sy-subrc eq 0.
* operations and conditions
endif
endif
endloop. " Loop at t_znbew into wa_znbew.
Thanks
Vivek
ā2013 Feb 21 9:18 PM
Hi Ojaswa,
It's good that u r trying things out. Based on the diagram flow, I'll try to help u with the concept.
Getting the code ready made for u is a bit of an exercise here.
-> loop / endlloop will take u to next combinations
-> dont use joins in any real time scenarios. Instead, Use for all entries and dont hesitate to do more processing in internal tables Using Read , Binary search
declare internal tables of standard types.
select * from znbew into table t_znbew
where fach = 'its' and behend = '31.12.9999'.
if sy-subrc eq 0.
select statement for zpatcore into table t_zpatcore for all entries in t_znbew
select statement for znpat into table t_znpat for all entries in t_zpatcore
endif.
sort the internal tables based on key fields.
Loop at t_znbew into wa_znbew.
read table t_zpatcore into wa_zpatcore
if sy-subrc eq 0 and wa_znbew-bettnr ne '-99'.
read table t_znpat into wa_znpat with key id = wa_znbew-patid.
if sy-subrc eq 0.
* operations and conditions
endif
endif
endloop. " Loop at t_znbew into wa_znbew.
Thanks
Vivek
ā2013 Feb 21 10:55 PM
Hi,
If your Z tables are large (or will become so in future), you would be much better off using JOINs.
cheers
Paul